//
//  CLPictorialCell.m
//  chanlin
//
//  Created by shuhui on 15-6-24.
//  Copyright (c) 2015年 chanlin. All rights reserved.
//

#import "CLPictorialCell.h"
#import "UIView+Utils.h"
#import "UIImageView+WebCache.h"

@interface CLPictorialCell()
@property (nonatomic, strong) UIImageView *titlePic;
@property (nonatomic, strong) UILabel *title;
@property (nonatomic, strong) UILabel *intro;
@property (nonatomic, strong) UIImageView *commentIcon;
@property (nonatomic, strong) UILabel *commentLab;

@end
@implementation CLPictorialCell


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        
        [self createView];
        
    }
    return self;
}

- (void)createView {
    
    //图
    if (!self.titlePic) {
        self.titlePic = [[UIImageView alloc]initWithFrame:CGRectMake(11, 12, 298, 128)];
        self.titlePic.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:self.titlePic];
    }
    
    //标题
    if (!self.title) {
        self.title = [[UILabel alloc] initWithFrame:CGRectMake(11, self.titlePic.bottom+12, GlobleWidth-55, 15)];
        self.title.backgroundColor = [UIColor clearColor];
        self.title.textColor = RGB(0x56, 0x56, 0x5e);
        self.title.font = [UIFont systemFontOfSize:15.f];
        self.title.textAlignment = NSTextAlignmentLeft;
        [self.contentView addSubview:self.title];
    }
    
    //介绍
    if (!self.intro) {
        self.intro = [[UILabel alloc] initWithFrame:CGRectMake(11, self.title.bottom+5, GlobleWidth-55, 12)];
        self.intro.backgroundColor = [UIColor clearColor];
        self.intro.textColor = RGB(0x87, 0x89, 0x88);
        self.intro.font = [UIFont systemFontOfSize:12.f];
        self.intro.textAlignment = NSTextAlignmentLeft;
        [self.contentView addSubview:self.intro];
    }
    
    //评论icon
    if (!self.commentIcon) {
        self.commentIcon = [[UIImageView alloc] initWithFrame:CGRectMake(GlobleWidth-47, self.titlePic.bottom+16, 12, 12)];
        self.commentIcon.backgroundColor = [UIColor clearColor];
        [self.commentIcon setImage:[UIImage imageNamed:@"index_commentCount_icon.png"]];
        [self.contentView addSubview:self.commentIcon];
    }
    
    //评论数
    if (!self.commentLab) {
        self.commentLab = [[UILabel alloc]initWithFrame:CGRectMake(self.commentIcon.right+4, self.commentIcon.top, 25, 10)];
        self.commentLab.backgroundColor = [UIColor clearColor];
        self.commentLab.textColor = RGB(0x5b, 0x85, 0x9e);
        self.commentLab.font = [UIFont systemFontOfSize:10.f];
        self.commentLab.textAlignment = NSTextAlignmentLeft;
        [self.contentView addSubview:self.commentLab];
    }
    
    //分割线
    UIImageView *seprateLine = [[UIImageView alloc]initWithFrame:CGRectMake(0, 196-0.5, GlobleWidth, 0.5)];
    seprateLine.backgroundColor = RGB(0xe0, 0xe0, 0xe0);
    [self.contentView addSubview:seprateLine];

    
}

- (void)loadData:(CLList *)newsList{
    [self.titlePic sd_setImageWithURL:[NSURL URLWithString:newsList.thumnail]
                     placeholderImage:[UIImage imageNamed:@"pictorial_default.png"]];
    
    self.title.text = _isStrNotNull(newsList.title)?newsList.title:@"";
    self.intro.text = _isStrNotNull(newsList.info)?newsList.info:@"";
    
    if (newsList.comment && newsList.comment>0) {
        self.commentIcon.hidden = NO;
        self.commentLab.hidden =NO;
        self.commentLab.text = [NSString stringWithFormat:@"%d",newsList.comment];
    }else{
        self.commentIcon.hidden = YES;
        self.commentLab.hidden =YES;
    }
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
